package com.lagou.edu.service.impl;

import com.lagou.edu.dao.ResumeDao;
import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;


@Service
public class ResumeServiceImpl implements ResumeService {
    @Autowired
    private ResumeDao resumeDao;

    @Override
    public List<Resume> findByPhone(String phone) {
        return resumeDao.findByPhone(phone);
    }

    @Override
    public List<Resume> findAll() {
        return resumeDao.findAll();
    }

    @Override
    public Resume findByOne(Resume resume) {
        Example<Resume> example = Example.of(resume);
        Optional<Resume> optionalResume = resumeDao.findOne(example);
        if (optionalResume.isPresent()){
            return optionalResume.get();
        }
        return null;
    }

    @Override
    public Resume findById(Long id) {
        return resumeDao.getOne(id);
    }

    @Override
    public Resume save(Resume resume) {
        return resumeDao.save(resume);
    }

    @Override
    public boolean deleteById(Long id) {
        resumeDao.deleteById(id);
        return true;
    }

    @Override
    public boolean deleteOne(Resume resume) {
        resumeDao.delete(resume);
        return true;
    }

    @Override
    public boolean deleteAll(Resume resume) {
        resumeDao.deleteAll();
        return true;
    }
}
